<template>
  <div class="main" v-loading="loading">
    <div class="filter" v-if="!type">
      <el-input placeholder="请输入客户名称" v-model="form.khname"></el-input>
      <el-input placeholder="请输入商品名称" v-model="form.spname"></el-input>
      <el-button type="primary" icon="el-icon-search" size="small" style="width: 100%;margin-bottom: 10px;"
                 @click="searchResult">搜 索
      </el-button>
    </div>
    <div class="result">
      <el-collapse>
        <el-collapse-item v-for="item in result" :title="item.khname" :key="item.khname">
          <el-row class="des-box">
            <el-col :span="5" class="des-title">商品编号</el-col>
            <el-col :span="4" class="des-content">{{ item.spbh }}</el-col>
            <el-col :span="6" class="des-title">商品名</el-col>
            <el-col :span="9" class="des-content">{{ item.spname }}</el-col>
            <el-col :span="5" class="des-title">件数</el-col>
            <el-col :span="4" class="des-content">{{ item.prnjs }}</el-col>
            <el-col :span="6" class="des-title">小数</el-col>
            <el-col :span="9" class="des-content">{{ item.prnxs }}</el-col>
            <el-col :span="5" class="des-title">金额</el-col>
            <el-col :span="4" class="des-content">{{ item.je }}</el-col>
            <el-col :span="6" class="des-title">价格</el-col>
            <el-col :span="9" class="des-content">{{ item.jg }}</el-col>
            <el-col :span="5" class="des-title">进价</el-col>
            <el-col :span="4" class="des-content">{{ item.jj }}</el-col>
            <el-col :span="6" class="des-title">日期</el-col>
            <el-col :span="9" class="des-content">{{ item.rq }}</el-col>
          </el-row>
        </el-collapse-item>
      </el-collapse>
    </div>
  </div>
</template>

<script>
import {queryGoodsHistory,queryGoodsCustomHistory} from "@/api/goods";

export default {
  name: "HistoryPrice",
  data() {
    return {
      type: 0, // 0为直接打开,1为商品页跳转过来
      result: [],
      loading: false,
      form: {
        khname: '',
        spname: ''
      }
    }
  },
  methods: {
    searchResult() {
      if(this.form.khname !== '' && this.form.spname !== ''){
        this.loading = true
        queryGoodsCustomHistory(this.form).then(res=>{
          if(res.code === 200){
            this.result = res.data
            if (res.data.length === 0) {
              this.$toast.open({
                message: '无数据',
                type: 'warning',
                duration: 2000,
                dismissible: true,
                position: 'top'
              })
            }
          }
        }).finally(()=>{
          this.loading = false
        })
      } else {
        this.$message.error('请输入筛选条件，二者不能为空')
      }
    }
  },
  created() {
    this.$nextTick(() => {
      if (this.$route.query.spbh) {
        this.type = 1
        queryGoodsHistory(this.$route.query.spbh).then(res => {
          if (res.code === 200) {
            this.result = res.data
          }
        })

        this.$buryingPoint('商品历史价格查询', this.$route.query.spbh)
      }

    })
  }
}
</script>

<style lang="scss" scoped>
.main {
  max-width: 600px;
  padding: 10px;

  .filter {
    .el-input {
      margin-bottom: 10px;
    }
  }
}

.result {

  .des-box {
    border-top: 1px solid #6595c7;
    border-left: 1px solid #6595c7;
  }

  .des-title {
    height: 32px;
    background-color: #c1d7ea;
    display: flex;
    align-items: center;
    padding-left: 10px;
    border-bottom: 1px solid #6595c7;
    border-right: 1px solid #6595c7;
  }

  .des-content {
    height: 32px;
    display: flex;
    align-items: center;
    padding-left: 10px;
    border-bottom: 1px solid #6595c7;
    border-right: 1px solid #6595c7;
  }
}
</style>
